package com.iflytek.application.common.springdata.jdbc.repository;

import com.iflytek.application.common.springdata.jdbc.repository.support.PageHelper;
import org.springframework.beans.factory.InitializingBean;

import java.sql.Connection;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Created by guanxf on 2016/3/14.
 */
public interface JdbcRepository extends InitializingBean {
	/**
	 * sql带group by 的分页查询
	 * @param clazz
	 * @param sql
	 * @param pager
	 * @param  objects
	 * @return
	 * @throws NumberFormatException
	 * @throws Exception
	 */
	Vector executeWithGorup(Class<?> clazz, String sql, PageHelper pager,Object... objects) throws  Exception;

	/***
	 *
	 * @param clazz
	 * @param sql
	 * @param pager
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	Vector executePager(Class<?> clazz, String sql, PageHelper pager, Object... objects) throws Exception;


	/**
	 * @param sql
	 * @param pagesize
	 * @param currentpage
	 * @return
	 */
	Vector executePager(String sql, int pagesize, int currentpage);

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeSql(Connection conn, String strSql, Object... objects) throws Exception;

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeSql(String strSql, Object... objects) throws Exception;

	/**
	 * @param sql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeBatch(String sql, Object... objects) throws Exception;

	/**
	 * 普通查询，不带分页 自带连接
	 * @param  clazz
	 * @param sql
	 * @param  objects
	 * @return
	 */
	Vector execute(Class<?> clazz, String sql, Object... objects);
	/**
	 * 普通查询，手动关闭连接
	 * @param con
	 * @param  clazz
	 * @param sql
	 * @param  objects
	 * @return
	 */
	Vector execute(Connection con, Class<?> clazz, String sql, Object... objects);
	/**
	 * 普通查询，不带分页 自带连接
	 * @param  clazz
	 * @param sql
	 * @param  objects
	 * @return
	 */
	Object executeForOne(Class<?> clazz, String sql, Object... objects);


	/**
	 * @param sql
	 * @param pager
	 * @param  objects
	 * @return
	 * @throws NumberFormatException
	 * @throws Exception
	 */
	Vector executePagerForMap(String sql, PageHelper pager, Object... objects) throws Exception;

	/**
	 * 执行查询语句。
	 * @param strSql 任何格式的查询语句
	 * @retrun Vector 对象,包含名/值对（hashtable格式类型）的结果
	 */
	Vector<Hashtable> executeForMap(String strSql) throws Exception;

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	Vector<Hashtable> executeForMap(String strSql, Object... objects)
			throws Exception;

	/**
	 * 执行insert update SQL。 单句时末尾无<b>。
	 * @return bRet 如果执行成功返回true，否则false。
	 * @param strSql 要执行的单句SQL或begin ...end语句。
	 */
	boolean executeUpdate(String strSql) throws Exception;

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeUpdate(String strSql, Object... objects) throws Exception;

	/**
	 * 自建连接的update 手动关闭连接
	 * @param con
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeUpdate(Connection con, String strSql, Object... objects) throws Exception;

	/**
	 * @param sql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeBatchUpdate(String sql, Object... objects) throws Exception;

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	boolean executeUpdateByConn(Connection conn, String strSql, Object... objects) throws Exception;

	/**
	 * @param strSql
	 * @param  objects
	 * @return
	 * @throws Exception
	 */
	Vector<Hashtable> execute(String strSql, Object... objects) throws Exception;

	/***
	 *
	 * @param conn
	 * @param sql
	 * @param objects
	 * @return
	 */
	Vector execute(Connection conn, String sql, Object... objects);

	/**
	 *
	 * @param sql
	 * @param objects
	 * @return
	 */
	Object getSingle(String sql, Object... objects);

	/**
	 * @param strSql 单查询，手动关闭连接
	 * @return int
	 * @throws Exception
	 */
	Object getSingle(Connection conn, String strSql) throws Exception;

	/***
	 * @param tablename
	 * @return
	 */
	String getMaxId(String tablename);
}
